﻿using BCCommon;
using BCEntity.OA.WorkflowActive.WorkflowActivitySpecificFormExecuteRecord;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;

namespace BCData.OA.WorkflowActivity.WorkflowActivitySpecificFormExecuteRecord
{
    public class WorkflowActivitySpecificFormExecuteRecordData : IWorkflowActivitySpecificFormExecuteRecordData
    {
        private readonly IDatabaseContext database;

        private const string QUERY = @"SELECT WorkflowActivitySpecificFormExecuteRecordId,WorkflowActivityId,FormTable,BoundField,BoundFieldValue,CreateTime 
                                    FROM OA_WorkflowActivitySpecificFormExecuteRecord";

        public WorkflowActivitySpecificFormExecuteRecordData(IDatabaseContext database)
        {
            this.database = database;
        }

        public async Task<IEnumerable<WorkflowActivitySpecificFormExecuteRecordEntity>> GetByWorkflowActivityId(long workflowActivityId)
        {
            return await database.Slave.QueryAsync<WorkflowActivitySpecificFormExecuteRecordEntity>($"{QUERY} WHERE WorkflowActivityId = ?WorkflowActivityId", new { workflowActivityId });
        }

        public async Task<WorkflowActivitySpecificFormExecuteRecordEntity> Insert(WorkflowActivitySpecificFormExecuteRecordEntity entity)
        {
            return await database.Master.InsertAsync(entity);
        }
    }
}
